﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.Utils;
using POS.Framework;
using Model.Bill;
using DevExpress.Xpo;
using BLL;
using DevExpress.Data.Filtering;

namespace POS.ModForm.Bill
{
    public partial class frmStoreHouseIn : DevExpress.XtraEditors.XtraForm
    {
        public frmStoreHouseIn()
        {
            InitializeComponent();
        }
        private void frmStoreHouseIn_Load(object sender, EventArgs e)
        {
            using (WaitDialogForm wdf = new WaitDialogForm(MsgBox.WaitLoading))
            {
                this.gridView.CustomDrawRowIndicator += new DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventHandler(SpecialGridView.DrawRowIndicator);
                //this.repositoryItemLookUpEdit_Status.DataSource = EnumManage.GetDictionaryEntry(typeof(EnterWarehouseStatus));
                SetButtonClickEvent();
                SearchData();
                wdf.Close();
            }
        }
        void SetButtonClickEvent()
        {
            this.listButtonUC.Query.Click += new EventHandler(Query_Click);
            this.listButtonUC.New.Click += new EventHandler(gridView_DoubleClick);

            this.gridView.DoubleClick += new EventHandler(gridView_DoubleClick);
            this.gridView.KeyPress += new KeyPressEventHandler(gridView_DoubleClick);
        }
        void gridView_DoubleClick(object sender, EventArgs e)
        {
            object oid = null;
            if (SpecialGridView.IsSimpleButton(sender) == false)
            {
                if (gridView.FocusedRowHandle < 0) return;
                oid = gridView.GetRowCellValue(gridView.FocusedRowHandle, "StoreHouseInID");
            }
            FormFactory.OpenForm("POS.ModForm.Bill.frmStoreHouseInForm", "入库单编辑", oid, this.MdiParent);
        }
        void Query_Click(object sender, EventArgs e)
        {
            using (WaitDialogForm wdf = new WaitDialogForm(MsgBox.WaitLoading))
            {
                SearchData();
                wdf.Close();
            }
        }
        void SearchData()
        {
            DevExpress.Data.Filtering.GroupOperator goFilter = new DevExpress.Data.Filtering.GroupOperator();
            if (!string.IsNullOrEmpty(this._CreateDT.Text))
                goFilter.Operands.Add(CriteriaOperator.Parse("CreatedDate>='" + this._CreateDT.Text + "'"));
            if (!string.IsNullOrEmpty(this._CreateDTEnd.Text))
                goFilter.Operands.Add(CriteriaOperator.Parse("CreatedDate<='" + this._CreateDTEnd.Text + " 23:58:58'"));
            if (!string.IsNullOrEmpty(this._BillDate.Text))
                goFilter.Operands.Add(CriteriaOperator.Parse("BillDate>='" + this._BillDate.Text + "'"));
            if (!string.IsNullOrEmpty(this._BillDateEnd.Text))
                goFilter.Operands.Add(CriteriaOperator.Parse("BillDate<='" + this._BillDateEnd.Text + " 23:58:58'"));
            //if (!string.IsNullOrEmpty(this._BillCode.Text.Trim()))
            //    goFilter.Operands.Add(CriteriaOperator.Parse("BillCode=?", this._BillCode.Text.Trim()));

            XPCollection<TB_StoreHouseIn> storage = new XPCollection<TB_StoreHouseIn>(DatabaseSchema.Session, goFilter);
            this.gridControl.DataSource = storage;
            SpecialGridView.SetGridViewIndicatorWidth(storage.Count, this.gridView);
        }
    }
}